home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / ODF / OS / FWGraphx / PRGDev.h < prev    next >
Encoding:
Text File  |  1996-12-16  |  9.8 KB  |  357 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                PRGDev.h
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef PRGDEV_H
  11. #define PRGDEV_H
  12.  
  13. #ifndef SLGRDEF_H
  14. #include "SLGrDef.h"
  15. #endif
  16.  
  17. #ifndef SLGDEV_H
  18. #include "SLGDev.h"
  19. #endif
  20.  
  21. #ifndef FWGCONST_H
  22. #include "FWGConst.h"
  23. #endif
  24.  
  25. #ifndef FWPOINT_H
  26. #include "FWPoint.h"
  27. #endif
  28.  
  29. #ifndef FWCOLOR_H
  30. #include "FWColor.h"
  31. #endif
  32.  
  33. #ifndef PRSHATTR_H
  34. #include "PRShAttr.h"
  35. #endif
  36.  
  37. #ifndef PRGRREF_H
  38. #include "PRGrRef.h"
  39. #endif
  40.  
  41. #if defined(FW_BUILD_WIN) && !defined(FWGDIOBJ_H)
  42. #include "FWGDIObj.h"
  43. #endif
  44.  
  45. #ifdef SelectFont
  46. #undef SelectFont    // Macro in Windowsx.h
  47. #endif
  48.  
  49. // ----- Foundation Includes -----
  50.  
  51. #ifndef FWREFCNT_H
  52. #include "FWRefCnt.h"
  53. #endif
  54.  
  55. // ----- OpenDoc Includes -----
  56.  
  57. #ifndef SOM_ODCanvas_xh
  58. #include <Canvas.xh>
  59. #endif
  60.  
  61. #ifndef SOM_ODTransform_xh
  62. #include <Trnsform.xh>
  63. #endif
  64.  
  65. #if defined(FW_BUILD_WIN) && !defined(SOM_ODPlatformCanvas_xh)
  66. #include <PlatCanv.xh>
  67. #endif
  68.  
  69. //========================================================================================
  70. //    Forward Declarations
  71. //========================================================================================
  72.  
  73. class    ODShape;
  74. class    FW_CPoint;
  75. class    FW_CRect;
  76. class    FW_CPlatformRect;
  77. class    FW_CPlatformPoint;
  78.  
  79. struct    FW_SGraphicContext;
  80.  
  81. //========================================================================================
  82. //    Shape Types
  83. //========================================================================================
  84.  
  85. enum FW_EPrivShapeCategories
  86. {
  87. #ifdef FW_BUILD_MAC
  88.     FW_kLineShape,            // Line
  89.     FW_kGeometricShape,        // Rect, Oval, Arc, RoundRect, Region
  90.     FW_kTypographicShape,    // Text
  91.     FW_kImageShape            // Bitmap, Picture
  92. #endif
  93. #ifdef FW_BUILD_WIN
  94.     FW_kGeometricShapeWithInvert,    // Rect, Region
  95.     FW_kGeometricShape,                // Line, RoundRect, Oval, Arc
  96.     FW_kTypographicShape,            // Text
  97.     FW_kImageShape                    // Bitmap, Picture
  98. #endif
  99. };
  100.  
  101.  
  102. //========================================================================================
  103. //    Forward declarations
  104. //========================================================================================
  105.  
  106. struct FW_SGraphicContext;
  107.  
  108. //========================================================================================
  109. //    struct FW_SPrivDeviceState
  110. //========================================================================================
  111.  
  112. struct FW_SPrivDeviceState
  113. {
  114. #ifdef FW_BUILD_WIN
  115.     POINT                    fWindOrg;
  116.     WORD                    fMapMode;
  117. #endif
  118. #ifdef FW_BUILD_MAC
  119.     // ----- if our port is not the current port fPreviousPlatformCanvas != NULL -----
  120.     FW_PlatformCanvas        fPreviousPlatformCanvas;
  121.     
  122.     // ----- if our port was the current port (fPreviousPlatformCanvas==NULL) save its state below -----
  123.     ODRgnHandle                fClip;
  124.     Point                    fOrigin;
  125.     
  126.     FW_Boolean                fSuspended;
  127.  
  128.     FW_SGraphicContext*        fSavedContext;
  129. #endif
  130. };
  131.  
  132. //========================================================================================
  133. //    struct FW_SPrivSuspendResumeState
  134. //========================================================================================
  135.  
  136. #ifdef FW_BUILD_WIN
  137. struct FW_SPrivSuspendResumeState
  138. {
  139.     int                        fSavedDC;
  140.     FW_SGraphicContext*        fSavedContext;
  141. };
  142. #endif
  143.  
  144. #ifdef FW_BUILD_MAC
  145. #define FW_SPrivSuspendResumeState    FW_SPrivDeviceState
  146. #endif
  147.  
  148. //========================================================================================
  149. //    class FW_CPrivGraphicsDevice
  150. //========================================================================================
  151.  
  152. class    FW_CPrivGraphicsDevice : public FW_CPrivGrRefObj
  153. {
  154. //---------------------------------------------------------------------------------------
  155. //    Constructor/Destructor
  156. //
  157. public:
  158.     FW_DECLARE_AUTO(FW_CPrivGraphicsDevice)
  159.  
  160.                             FW_CPrivGraphicsDevice(ODCanvas* odCanvas);
  161.                             FW_CPrivGraphicsDevice(FW_PlatformCanvas platformCanvas);
  162.     
  163.     virtual                 ~FW_CPrivGraphicsDevice();
  164.  
  165. //---------------------------------------------------------------------------------------
  166. //    API
  167. //
  168. public:
  169.     FW_PlatformCanvas        GetPlatformCanvas() const;
  170.     operator                 FW_PlatformCanvas() const;
  171.  
  172.     ODCanvas*                 GetODCanvas() const;
  173.  
  174.     FW_SPrivDeviceState*    OpenDevice(Environment *ev, FW_SGraphicContext* context);
  175.     void                     CloseDevice(Environment *ev, FW_SPrivDeviceState* deviceState);
  176.     
  177.     ODRgnHandle             GetClip() const;                                            // return a copy
  178.     void                    GetClipRect(FW_CPlatformRect& clipRect) const;
  179.  
  180.     void                     SetClip(Environment* ev, ODRgnHandle clipRegion);                            // Use a copy
  181.     void                    SetClipRect(const FW_CPlatformRect& clipRect);
  182.     void                    IntersectClipRect(Environment* ev, const FW_CPlatformRect& clipRect);
  183.  
  184.     void                    SetOrigin(Environment* ev, FW_CPlatformPoint origin);
  185.     
  186.     FW_SPrivDeviceState*    GetState();
  187.     
  188.     FW_SPrivSuspendResumeState*    Suspend();
  189.     void                    Resume(FW_SPrivSuspendResumeState *suspendResumeState);
  190.                                                         
  191.     void                    CanvasChanged(Environment *ev, ODCanvas* odCanvas);
  192.     void                    MappingChanged(Environment* ev);
  193.     
  194.     // ----- Return the resolution in dpi -----
  195.     FW_CPoint                GetResolution() const;
  196.     void                    SetResolution(FW_Fixed x, FW_Fixed y);
  197.     
  198.     void                    UpdateOriginForContext(Environment* ev);
  199.                                      
  200. //----------------------------------------------------------------------------------------
  201. //    Data Members
  202. //
  203. protected:
  204.     ODCanvas*                 fODCanvas;            // Might be NULL
  205.     FW_PlatformCanvas         fPlatformCanvas;
  206.     short                    fOpenDeviceCount;
  207.     
  208.     FW_CPoint                 fResolution;
  209.  
  210.     FW_Boolean                fSuspended;
  211.     
  212.     FW_SGraphicContext*        fContext;
  213.     
  214. //----------------------------------------------------------------------------------------
  215. //    Platform Specific API
  216. //
  217. #ifdef FW_BUILD_WIN
  218. public:
  219.     void                    SelectFont(const FW_HFont font, FW_Boolean scale);
  220.  
  221.     FW_Boolean                IsMetaFileCanvas() const;
  222.  
  223.     // ----- Settings -----    
  224.     void                    SelectInkAndFont(const FW_HInk ink, 
  225.                                             const FW_HFont font);
  226.     FW_Boolean                SelectInkAndStyle(const FW_HInk ink, 
  227.                                             const FW_HStyle style,
  228.                                             FW_EPrivShapeCategories shapeType, 
  229.                                             FW_ERenderVerbs renderVerb);
  230.                                             
  231.     void                    SetTextColor(COLORREF textColor);    
  232.     void                    SetBkColor(COLORREF bkColor);
  233.     
  234. protected:
  235.     // ----- We don't bother doing any caching for those, they should be pretty fast -----
  236.     void                    SetDrawingMode(int drawingMode)
  237.                                 {::SetROP2(fDC, drawingMode);}
  238.     void                    SetBkMode(int bkMode)
  239.                                 {::SetBkMode(fDC, bkMode);}
  240. #endif
  241. #ifdef FW_BUILD_MAC                                    
  242. public:
  243.     // ----- Settings -----
  244.     void                    SelectInk(const FW_HInk ink, 
  245.                                 FW_EPrivShapeCategories shapeCategory, 
  246.                                 FW_ERenderVerbs renderVerb);
  247.     void                    SelectStyle(const FW_HStyle style, 
  248.                                 FW_TransferModes transferMode,
  249.                                 FW_Boolean& styleIsDash,
  250.                                 FW_Boolean& styleIsHairline);
  251.     void                    SelectFont(const FW_HFont font, 
  252.                                 FW_Boolean scale);
  253.  
  254.     void                    SetInGrafPort();
  255.     void                    ResetSettings();
  256.     
  257.     // Values for fChangeFlag
  258.     enum
  259.     {
  260.         FW_kForeColorChanged     =    0x0001,
  261.         FW_kBackColorChanged    =    0x0002,
  262.         FW_kHiliteColorChanged    =    0x0004,
  263.         FW_kPatternChanged        =    0x0008
  264.     };
  265.  
  266.     void                    SetForeColor(const FW_CColor& foreColor)
  267.                                 {fForeColor = foreColor; fChangeFlag |= FW_kForeColorChanged;}
  268.     void                    SetBackColor(const FW_CColor& backColor)
  269.                                 {fBackColor = backColor; fChangeFlag |= FW_kBackColorChanged;}
  270.     void                    SetHiliteColor(const FW_CColor& hiliteColor)
  271.                                 {fHiliteColor = hiliteColor; fChangeFlag |= FW_kHiliteColorChanged;}
  272.     void                    SetPattern(const FW_HPattern pattern);
  273.     void                    SetPenSize(short hPenSize, short vPenSize)
  274.                                 {fHPenSize = hPenSize; fVPenSize = vPenSize;}
  275.     void                    SetFontID(short fontID)
  276.                                 {fFontID = fontID;}
  277.     void                    SetFontSize(short fontSize)
  278.                                 {fFontSize = fontSize;}
  279.     void                    SetFontStyle(Style fontStyle)
  280.                                 {fFontStyle = fontStyle;}
  281.     void                    SetPenMode(short penMode)
  282.                                 {fPenMode = penMode;}
  283.     void                    SetTextMode(short textMode)
  284.                                 {fTextMode = textMode;}
  285.     
  286. private:                            
  287.     void                    MacBeginPostScriptClip(Environment* ev, RgnHandle rgn);
  288.     void                    MacEndPostScriptClip();
  289. #endif
  290.  
  291. //----------------------------------------------------------------------------------------
  292. //    Platform Specific Data Members
  293. //
  294. #ifdef FW_BUILD_WIN
  295. public:
  296.     // ----- HDC -----
  297.     HDC                        fDC;
  298.  
  299.     // ----- Settings -----
  300.     COLORREF                fTextColor;
  301.     COLORREF                fBkColor;
  302.     FW_CPlatformPoint        fPenSize;    // Used for frame with brush
  303.  
  304.     // ----- Brush/Pen/Font -----
  305.     FW_CPrivWinGDIPen        fGDIPen;
  306.     FW_CPrivWinGDIBrush        fGDIBrush;
  307.     FW_CPrivWinGDIFont        fGDIFont;
  308. #endif
  309. #ifdef FW_BUILD_MAC
  310. public:
  311.     // ----- Device Settings -----
  312.     FW_CColor                 fForeColor;
  313.     FW_CColor                fBackColor;
  314.     FW_CColor                fHiliteColor;
  315.     FW_PPrivPattern            fPattern;
  316.     short                    fHPenSize;
  317.     short                    fVPenSize;
  318.     short                    fFontID;
  319.     short                    fFontSize;
  320.     Style                    fFontStyle;
  321.     short                    fPenMode;
  322.     short                    fTextMode;
  323.  
  324. private:
  325.     unsigned short            fChangeFlag;
  326.  
  327.     // ----- PostScript clipping
  328.     FW_Boolean                fMacPostScriptClip;
  329. #endif
  330. };
  331.  
  332. //---------------------------------------------------------------------------------------
  333. //    FW_CPrivGraphicsDevice::GetODCanvas
  334. //---------------------------------------------------------------------------------------
  335. inline ODCanvas* FW_CPrivGraphicsDevice::GetODCanvas() const
  336. {
  337.     return fODCanvas;
  338. }
  339.  
  340. //---------------------------------------------------------------------------------------
  341. //    FW_CPrivGraphicsDevice::GetPlatformCanvas
  342. //---------------------------------------------------------------------------------------
  343. inline FW_PlatformCanvas FW_CPrivGraphicsDevice::GetPlatformCanvas() const
  344. {
  345.     return fPlatformCanvas;
  346. }
  347.  
  348. //---------------------------------------------------------------------------------------
  349. //    FW_CPrivGraphicsDevice::operator FW_PlatformCanvas
  350. //---------------------------------------------------------------------------------------
  351. inline FW_CPrivGraphicsDevice::operator FW_PlatformCanvas() const
  352. {
  353.     return fPlatformCanvas;
  354. }
  355.  
  356. #endif
  357.